package com.liujit.bms.admin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liujit.bms.admin.domain.model.BlogMemberCollection;
import com.liujit.bms.admin.domain.query.BlogMemberCollectionQuery;
import com.liujit.bms.admin.domain.result.BlogMemberCollectionResult;
import com.liujit.bms.admin.mapper.BlogMemberCollectionMapper;
import com.liujit.bms.admin.service.BlogMemberCollectionService;
import com.liujit.common.domain.result.PageBean;
import com.liujit.common.utils.Pagination;
import org.springframework.stereotype.Service;

/**
 * @Description 博客会员收藏Service实现类
 * @Author liujun
 * @Date 2021-07-19 17:50:23
 */
@Service
public class BlogMemberCollectionServiceImpl extends ServiceImpl<BlogMemberCollectionMapper, BlogMemberCollection>
        implements BlogMemberCollectionService {

    @Override
    public PageBean<BlogMemberCollectionResult> getPage(BlogMemberCollectionQuery query) {
        Page<BlogMemberCollection> page = Pagination.page(query);
        LambdaQueryWrapper<BlogMemberCollection> wrapper = new LambdaQueryWrapper();
        wrapper.eq(BlogMemberCollection::getMemberId, query.getMemberId());
        if (StrUtil.isNotBlank(query.getTitle())) {
            wrapper.like(BlogMemberCollection::getTitle, query.getTitle());
        }
        if (query.getStartTime() != null) {
            wrapper.ge(BlogMemberCollection::getCollectionTime, query.getStartTime());
        }
        if (query.getEndTime() != null) {
            wrapper.le(BlogMemberCollection::getCollectionTime, query.getEndTime());
        }
        IPage<BlogMemberCollection> iPage = super.page(page, wrapper);
        return PageBean.page(iPage, BlogMemberCollectionResult.class);
    }
}
